package com.yan.demo;

import com.yan.demo.domain.Student;

import java.io.*;

/**
 * @author taoge
 * @Date 2024/8/6 14:14
 * @Description 对象流
 */
public class Demo4 {
    public static void main1(String[] args) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day12_code/src/com/yan/demo/Student.txt"));
        Student stu = new Student("jack", 18);
        oos.writeObject(stu);
        oos.close();

        //ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day12_code/src/com/yan/demo/Student.txt"));

        }


    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day12_code/src/com/yan/demo/Student.txt"));
        Object o = ois.readObject();
        if(o instanceof Student){
            Student stu = (Student) o;
            System.out.println(o);
        }
    }
 }
